package com.class04.config;

import com.class04.interceptor.MyInterceptor;
import com.class04.interceptor.MyInterceptor1;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @ClassDescription:
 * 项目的配置类，controller、handlermapping handlerAdapater
 * 加入ioc容器
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/4 8:07
 */
@EnableWebMvc
@ComponentScan({"com.class04.controller","com.class04.error"})
@Configuration
public class MvcConfig implements WebMvcConfigurer {
//    handlerMapping handlerAdapter
//    中配置视图解析器  指定前后缀
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
//        registry可以快速添加前后缀
        registry.jsp("/WEB-INF/views/",".jsp");
//        handler -> index
    }
//   开启静态资源查找

    @Override
    public void configureDefaultServletHandling
            (DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置方案1：拦截全部请求
//        registry.addInterceptor(new MyInterceptor());
        //配置方案2：指定地址拦截
//        addPathPatterns("/hello/test2")
//        * 任意一层字符串   **任意多层字符串
//        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/hello/**");
        //配置方案3：排除拦截  排除的地址应该拦截地址内部
//        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/hello/**").excludePathPatterns("/hello/test2");


        registry.addInterceptor(new MyInterceptor());
        registry.addInterceptor(new MyInterceptor1());
    }
}
